home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / communic / pcmail / main / gp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  5.7 KB  |  178 lines

  1. /*++
  2. /* NAME
  3. /*    gp 5
  4. /* SUMMARY
  5. /*    g-protocol internal definitions
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    cico
  10. /* SYNOPSIS
  11. /*    #include "gp.h"
  12. /* DESCRIPTION
  13. /* .nf
  14.  
  15.  /* include-once file */
  16.  
  17. #ifndef    GP
  18. #define    GP
  19.  
  20. #include <stdio.h>            /* needed for stderr */
  21.  
  22. #define    MAXTRY        10        /* max nr of retries */
  23. #define    CTRL(x)        ((x)^0100)    /* for ascii control characters */
  24. #define    MIN(x,y)    ((x) < (y) ? (x) : (y))
  25. #define    MAX(x,y)    ((x) > (y) ? (x) : (y))
  26.  
  27. #define    ALARM        10        /* time-out interval */
  28. #define    MAGIC        0xAAAA        /* checksum magic number */
  29. #define    KCTRL        9        /* control packet */
  30.  
  31. #define    FAIL        (-1)        /* corrupted packet */
  32. #define    TIME        (-2)        /* timed out */
  33.  
  34.  /* 
  35.   * The protocol is defined in terms of message transmissions of 8-bit
  36.   * bytes. Each message includes one control byte plus a data segment
  37.   * of zero or more information bytes. (...)
  38.   * The control byte is partitioned into three fields as depicted below.
  39.   *    bit    7    6    5    4    3    2    1    0
  40.   *        t    t    x    x    x    y    y    y
  41.   * The t bits indicate a packet type and determine the interpretation
  42.   * to be placed on the xxx and yyy the fields. The various interpretations
  43.   * are as follows:
  44.   *    tt    interpretation
  45.   *    00    control packet
  46.   *    10    data packet
  47.   *    11    short data packet
  48.   *    01    alternate channel
  49.   * A data segment accompanies all non-control packets. (...) Type 01 packets
  50.   * are never used by UUCP (...)
  51.   */
  52.  
  53. #define    TYPE(x)        ((x)&0300)    /* extract message field */
  54.  
  55. #define    CONTROL        0000        /* control message */
  56. #define    DATA        0200        /* data, fixed size */
  57. #define    SHORT        0300        /* short (variable) length data */
  58. #define    ALTCH        0100        /* alternate channel (unused) */
  59.  
  60.  /*
  61.   * The sequence number of a non-control packet is given by the xxx field.
  62.   * Control packets are not sequenced. The newest sequence number,
  63.   * excluding duplicate transmissions, accepted by a receiver is placed in 
  64.   * the yyy field of non-control packets sent to the `other' receiver.
  65.   */
  66.  
  67. #define    TVAL(x)        (((x)&0377)>>6)    /* extract message type */
  68. #define    MVAL(x)        (((x)&070)>>3)    /* extract control message */
  69. #define    SVAL(x)        (((x)&070)>>3)    /* extract S(equence) value */
  70. #define    RVAL(x)        ((x)&07)    /* extract R(received) value */
  71. #define    IVAL(x)        ((x)&07)    /* extract init value */
  72. #define    SFLD(x)        (((x)&07)<<3)    /* create S(equence) field */
  73. #define    RFLD(x)        ((x)&07)    /* create R(received) field */
  74. #define    IFLD(x)        ((x)&07)    /* create init field */
  75.  
  76.  /*
  77.   * There are no data bytes associated with a control packet, the xxx field
  78.   * is interpreted as a control message, and the yyy field is a value 
  79.   * accompanying the control message. The control messages are listed
  80.   * below in decreasing priority. That is, if several control messags
  81.   * are to be sent, the lower-numbered ones are sent first.
  82.   *    xxx    name    yyy
  83.   *    1    CLOSE    n/a
  84.   *    2    RJ    last correctly received sequence number
  85.   *    3    SRJ    sequence number to retransmit
  86.   *    4    RR    last correctly received sequence number
  87.   *    5    INITC    window size
  88.   *    6    INITB    data segment size
  89.   *    7    INITA    window size
  90.   */
  91.  
  92. #define    MESG(x)        ((x)&070)    /* extract control message field */
  93.  
  94. #define    CLOSE        0010        /* close message */
  95. #define    RJ        0020        /* reject message */
  96. #define    SRJ        0030        /* selective-reject message (unused) */
  97. #define    RR        0040        /* received ok message */
  98. #define    INITC        0050        /* initialization message */
  99. #define    INITB        0060        /* initialization message */
  100. #define    INITA        0070        /* initialization message */
  101.  
  102.  /* declarations for tiny systems without tty driver, timer support etc. */
  103.  
  104. #ifndef    unix
  105.  
  106. #define    read        xread
  107. #define    write        xwrite
  108. #define    alarm(x)    /* nothing */
  109. #define    signal(x,y)    /* nothing */
  110. #define    DEBUG(x,y,z)    if (dflag >= x) printf(y,z)
  111.  
  112. extern int dflag;
  113.  
  114. #else
  115.  
  116. #define    DEBUG(l,f,s)    if (Debug >= l) fprintf(stderr,f,s)
  117.  
  118. extern int Debug;
  119.  
  120. #endif
  121.  
  122.  /* 
  123.   * We use one data structre for communication between various levels
  124.   * of the g-protocol implementation. Fields in parentheses are relevant
  125.   * only when a packet holds data.
  126.   *    field    meaning                set by
  127.   *    c    message type            gwrite(), grpack()
  128.   *    (k    data segment length        galloc(), grpack())
  129.   *    (chk    16-bit checksum            packet i/o functions)
  130.   *    (len    max. data segment length    galloc(), gwrite(), grpack())
  131.   *    (data    start of "len" bytes        this field is fixed)
  132.   *    (segl    nbr of data bytes left        gread())
  133.   *    (segp    start of "segl" bytes        gread())
  134.   */
  135.  
  136.  /* structure for communication between various program layers */
  137.  
  138. typedef struct {
  139.     char k;                /* message segment size */
  140.     char c;                /* message type */
  141.     int chk;                /* data checksum */
  142.     short segl;                /* nr of data bytes left */
  143.     char *segp;                /* start of the "segl" bytes */
  144.     short len;                /* maximum data segment size */
  145.     char data[1];            /* actually a lot of characters */
  146. } Packet;
  147.  
  148.  /* functions that manipulate packets */
  149.  
  150. extern Packet *grproto();        /* take packet from input queue */
  151. extern void gfree();            /* release input packet */
  152. extern Packet *galloc();        /* allocate output packet */
  153. extern void gwproto();            /* place packet in output queue */
  154. extern void gfail();            /* panic button */
  155. extern void gsctrl();            /* send one control packet */
  156. extern void gsdata();            /* send one data packet */
  157. extern int grpack();            /* receive one packet */
  158.  
  159. extern int seglen[];            /* data segment size table */
  160.  
  161.  /* standard unix library */
  162.  
  163. extern char *malloc();
  164.  
  165. #endif    /* GP */
  166. /* AUTHOR(S)
  167. /*    W.Z. Venema
  168. /*    Eindhoven University of Technology
  169. /*    Department of Mathematics and Computer Science
  170. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  171. /* CREATION DATE
  172. /*    Sun Apr 19 12:41:37 GMT+1:00 1987
  173. /* LAST MODIFICATION
  174. /*    90/01/22 13:01:41
  175. /* VERSION/RELEASE
  176. /*    2.1
  177. /*--*/
  178.